Repository navigation
fix(studio): a sealed preview shows paused video frames from Studio's decoder - #8466
Conversation
Edit accuracy: accurate 271 (base branch 271), smooth 57 of thoseThe gate passes. Quarantined, measured but not gated (0) |
jrusso1020
left a comment
There was a problem hiding this comment.
Request changes, for one blocker. I reviewed at 15550fc2.
Need ✅ · Size ✅ · Reuse ✅ (setPausedVideoFrameProvider, PREVIEW_PATH and the decoder are reused; the frame-window lookup is gone) · Simpler ✅ · Structure
Risk: medium. Studio now decodes on a frame's behalf.
What holds up:
- Path checks.
projectFileOftakes only this project's preview route. It rejects.,..and empty segments after decoding, and turns away bad escapes. - File list. Every path is then looked up in the project's file list before anything is read.
- Studio builds the address. The URL is assembled on Studio's own origin with
encodeUrlPath. - Parameters.
parsePausedFrameAskkeeps only the four proxy parameters, withPARAM_VALUE-checked values, plus finite hints. - Images. They cross the port as transferred
ImageBitmapcopies. The decoder's frame is released infinally. - Tests: studio
pausedVideo*andplaybackAdapterResolutionpass 39/39. CorepausedFrames,editingAgentandeditingPortpass 177/177. Studiotscis clean, and CI is green.
Blocker: the "one decode in flight" cap doesn't hold after an abort.
pausedFrameHost deletes the id from inFlight the moment an abort arrives (port.onmessage, the abort branch). refusal() then sees an empty map and admits the next decode, while the aborted decoder.decode(...) is still running until it next checks its signal. The original call's finally no longer finds its entry, so nothing counts it.
Probe: a stub decoder whose decode never settles, then decode and abort five times on one port. decoder.decode was called 5 times, all running at once, where the body says "one decode in flight, so a second is refused, not queued". Each call can open up to PAUSED_FRAME_SOURCES readers, so the per-port limit is really unbounded.
Fix:
- On
abort, callcontrol.abort()but keep the entry. Let the decode's ownfinallyremove it once the call has actually ended. - Then a new ask will hit "busy" during a normal paused scrub. To keep that smooth, hold at most one waiting ask (newest wins, and it replaces an older waiting one) and start it when the slot frees, rather than refusing it.
- Add a test with a decoder that settles only after its signal fires, asserting
decodenever runs twice at once.
— Rames (hf-review)
jrusso1020
left a comment
There was a problem hiding this comment.
Re-review at d164050: approve.
My blocker from 15550fc is resolved. An abort message now only calls abort() on the controller. The one-decode slot is freed solely in decode's own finally, and inFlight.get(id) === control guards that delete. A second decode is therefore refused "Preview decoder busy" until the aborted one settles, and then it is served. close() still aborts and clears every slot, so a closed host cannot be held.
Red-first: verified. With pausedVideoProvider.ts at 15550fc, the new test "keeps an aborted decode's slot until that decode settles" fails (the second decode reaches the decoder). At head, pausedVideoProvider.test.ts and pausedVideoProvider.sealed.test.ts pass 11/11. Nothing else changed since 15550fc, which I reviewed in full.
Note, not blocking: a decoder that ignores its abort signal and never settles holds the slot until the host closes. That is the intended side for a one-at-a-time budget.
Need ✅ · Size ✅ · Reuse ✅ · Simpler ✅ (the fix is a deletion) · Structure ✅
Risk: low.
— Rames (hf-review)
What
A paused video in a sealed Studio preview (
VITE_STUDIO_OPAQUE_PREVIEW_ENABLED=1) now shows Studio's decoded frame, as it does unsealed. Before, the paused foreground showed the browser's own video element, because Studio's decoder was never installed in a frame it cannot script.Why
attachPausedVideoProviderinstalled the decoder by calling the frame'swindow.__hf.setPausedVideoFrameProviderand readiframe.contentDocument. A sealed frame has an opaque origin, so both are out of reach and the function returned early (pausedVideoProvider.ts:15on main). The preview-video-regression check fails sealed at its first paused step: "Paused foreground has no decoded canvas".How
One path for both modes:
MessageChannelper frame load. It hands one end to the runtime with a new editing request,serve-paused-frames { channel }, sent with a transfer list (the editing client'srequestgains atransferoption).setPausedVideoFrameProvider. Core's prepare and present code is unchanged.hf-proxy,hf-proxy-box,hf-proxy-light,hf-proxy-retry), never a URL. Frame rate and VFR go along as timing hints.PREVIEW_PATH, the frame-token route included), with no.,..or empty segment after decoding.PAUSED_FRAME_SOURCES(4, the decoder's reader budget) sources per decode;PAUSED_FRAME_BYTES(128 MB, the runtime's own present budget) of frames per reply.createImageBitmapcopies, transferred. The decoder's cached frame is released at once.sourceFactsOfSrc, so the decoder no longer reads the frame's window. Its private suffix lookup is gone.unknown-kind, and Studio closes the port. That preview keeps native frames, as sealed previews do today.Test plan
fails without the fix:
packages/studio/src/player/lib/pausedVideoProvider.sealed.test.ts("a sealed frame's runtime decodes paused frames through Studio, which reads only the project file")sealedPreviewFrameand drivesresolveFramePlaybackAdapter.expected "vi.fn()" to be called once, but got 0 times). With this branch, it passes 3 runs in a row.pausedVideoProvider.test.ts: Studio refuses each of these without calling the decoder:packages/core/src/runtime/editing/pausedFrames.test.ts: an ask carries only the path and the proxy's options, never another server's media. An abort is told to Studio, and dispose rejects what is pending.On the devbox, named tests 3 of 3 green; all 74 covering files green;
tscclean in core and studio; Fallow and pre-push clean.preview-video-regression on the devbox, Studio dev server, 2 runs per mode:
Cost: time from a paused one-frame seek to the decoded canvas showing that frame, 24 seeks per run, same fixture and same devbox, at this branch's base
c731046cvs this branch:The unsealed bitmap copy is within run-to-run noise.
Before
Sealed preview at this branch's base, paused at 2.000 s on the preview-video-regression fixture: the browser's own video element draws the frame. The regression check then fails with "Paused foreground has no decoded canvas".
After
The same frame with this change: Studio's decoded canvas draws it, as unsealed. The pictures match at this frame. The difference is which surface draws it: the decoded canvas is frame-exact at full source detail, which the regression check's frame step and detail checks assert.
Related work
Refs #7846 (the sealed-by-default preview).